package com.myapp.mobilesafe.activity;

import android.content.Intent;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

import com.myapp.mobilesafe.utils.PrefUtils;
import com.myapp.mobilesafe.view.SettingItemView;

public class SetupDirect02Activity extends BaseSetupActivity {
    private SettingItemView sivBindSIM;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setup_direct02);
        sivBindSIM = (SettingItemView) findViewById(R.id.siv_bindSIM);
        String bindSim = PrefUtils.getString("bind_sim",null,this);
        if(TextUtils.isEmpty(bindSim)){
            sivBindSIM.setChecked(false);
        }else {
            sivBindSIM.setChecked(true);
        }
        sivBindSIM.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(sivBindSIM.isChecked()){
                    sivBindSIM.setChecked(false);
                    PrefUtils.remove("bind_sim",getApplicationContext());
                }else {
                    sivBindSIM.setChecked(true);
                    TelephonyManager tm  = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
                    String simSerialNumber=tm.getSimSerialNumber();
                    Log.i("hahah","#$#$#$#$"+simSerialNumber);
                    PrefUtils.putString("bind_sim",simSerialNumber,getApplicationContext());
                }
            }
        });
    }
    @Override
    public void goBack() {
        startActivity(new Intent(this,SetupDirect01Activity.class));
        finish();
        overridePendingTransition(R.anim.anim_back_in, R.anim.anim_back_out);
    }
    @Override
    public void goNext() {
        String bindSim = PrefUtils.getString("bind_sim",null,this);
        if(TextUtils.isEmpty(bindSim)){
            Toast.makeText(this,"请先绑定SIM卡",Toast.LENGTH_SHORT).show();
            return;
        }
        startActivity(new Intent(this,SetupDirect03Activity.class));
        finish();
        overridePendingTransition(R.anim.anim_in, R.anim.anim_out);
    }
}
